package com.fms.controllers.treasurer;


import com.fms.model.BKLiquidationRegisterModel;
import com.fms.dao.BKLiquidationRegisterDAO;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;

public class BKLiquidationRegister extends WebPage {
	
	private Model bkl_idModel = new Model();
	private Model org_idModel = new Model();
	private Model dateModel = new Model();
	private Model officerModel = new Model();
	private Model lf_noModel = new Model();
	private Model rcv_noModel = new Model();
	private Model amount_advancedModel = new Model();
	private Model actual_amountModel = new Model();
	private Model amount_returnedModel = new Model();
	private Model date_createdModel = new Model();
	private Model uploaderModel = new Model();
	private Model statusModel = new Model();
	
	public BKLiquidationRegister(){
		Form bkLiquidationRegisterForm =  new Form ("bkLiquidationRegisterForm");
		
		TextField bkl_id = new TextField("bkl_id", bkl_idModel);
		bkl_id.setRequired(true);
		bkLiquidationRegisterForm.add(bkl_id);
		
		TextField org_id = new TextField("org_id", org_idModel);
		org_id.setRequired(true);
		bkLiquidationRegisterForm.add(org_id);
		
		TextField date = new TextField("date", dateModel);
		date.setRequired(true);
		bkLiquidationRegisterForm.add(date);
		
		TextField officer = new TextField("officer", officerModel);
		officer.setRequired(true);
		bkLiquidationRegisterForm.add(officer);
		
		TextField lf_no = new TextField("lf_no", lf_noModel);
		lf_no.setRequired(true);
		bkLiquidationRegisterForm.add(lf_no);
		
		TextField rcv_no = new TextField("rcv_no", rcv_noModel);
		rcv_no.setRequired(true);
		bkLiquidationRegisterForm.add(rcv_no);
			
		TextField amount_advanced = new TextField("amount_advanced", amount_advancedModel);
		amount_advanced.setRequired(true);
		bkLiquidationRegisterForm.add(amount_advanced);
		
		TextField actual_amount = new TextField("actual_amount", actual_amountModel);
		actual_amount.setRequired(true);
		bkLiquidationRegisterForm.add(actual_amount);
		
		TextField amount_returned = new TextField("amount_returned", amount_returnedModel);
		amount_returned.setRequired(true);
		bkLiquidationRegisterForm.add(amount_returned);
		
		TextField date_created = new TextField("date_created", date_createdModel);
		date_created.setRequired(true);
		bkLiquidationRegisterForm.add(date_created);
		
		TextField uploader = new TextField("uploader", uploaderModel);
		uploader.setRequired(true);
		bkLiquidationRegisterForm.add(uploader);
		
		TextField status = new TextField("status", statusModel);
		status.setRequired(true);
		bkLiquidationRegisterForm.add(status);
		
		add(bkLiquidationRegisterForm);
		
		Button bkLiquidationRegisterFormAdd = new Button ("bkLiquidationRegisterFormAdd"){
			
			public void onSubmit(){
				
				String nbkl_id = (String) bkl_idModel.getObject();
				String norg_id = (String) org_idModel.getObject();
				String date = (String) dateModel.getObject();
				String officer = (String) officerModel.getObject();
				String nlf_no = (String) lf_noModel.getObject();
				String nrcv_no = (String) rcv_noModel.getObject();
				String namount_advanced = (String) amount_advancedModel.getObject();
				String nactual_amount = (String) actual_amountModel.getObject();
				String namount_returned = (String) amount_returnedModel.getObject();
				String date_created = (String) date_createdModel.getObject();
				String uploader = (String) uploaderModel.getObject();
				String status = (String) statusModel.getObject();
				
				int bkl_id = Integer.parseInt(nbkl_id);
				int org_id = Integer.parseInt(norg_id);
				int lf_no = Integer.parseInt(nlf_no);
				int rcv_no = Integer.parseInt(nrcv_no);
				float amount_advanced = Float.valueOf(namount_advanced);
				float actual_amount = Float.valueOf(nactual_amount);
				float amount_returned = Float.valueOf(namount_returned);
				
				BKLiquidationRegisterModel bkLR = new BKLiquidationRegisterModel(bkl_id, org_id, date, officer, lf_no, rcv_no, amount_advanced,
						actual_amount, amount_returned, date_created, uploader, status);
				
				BKLiquidationRegisterDAO bkLRDAO = new BKLiquidationRegisterDAO ();
				bkLRDAO.insert(bkLR);
				
			}
			
		};
		
	}

}
